//
//  LYQCountrySelectView.m
//  ZCProject
//
//  Created by 崔明燃 on 16/11/30.
//  Copyright © 2016年 Zheng. All rights reserved.
//

#import "LYQCountrySelectView.h"

@implementation LYQCountrySelectView

- (instancetype)initWithFrame:(CGRect)frame {
    if (self = [super initWithFrame:frame]) {
        [self addSubview:self.countryInsideButton];
        [self addSubview:self.countryOutsideButton];
        [self addSubview:self.centerLineView];
        [self addSubview:self.downLineView];
        [self addSubview:self.bottomLineView];
        
        [self subViewsLayout];
    }
    
    return self;
}
#pragma mark - button Clicked 
- (void)countryButtonClicked:(UIButton *)button {
    switch (button.tag) {
        case 101:
        {
            [UIView animateWithDuration:0.25 animations:^{
                CGRect frame = self.downLineView.frame;
                frame.origin.x = self.center.x / 2 - 20;
                self.downLineView.frame = frame;
            }];
        }
            break;
        case 202:
        {
            [UIView animateWithDuration:0.25 animations:^{
                CGRect frame = self.downLineView.frame;
                frame.origin.x = ((self.width / 4 * 3) - 20);
                self.downLineView.frame = frame;
            }];
        }
            break;
        default:
            break;
    }
    
    
}
#pragma mark - layout subViews 
- (void)subViewsLayout {
    [_countryInsideButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.mas_top);
        make.left.equalTo(self.mas_left);
        make.right.equalTo(self.mas_centerX);
        make.height.equalTo(@(self.height));
    }];
    
    [_countryOutsideButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.mas_top);
        make.left.equalTo(self.mas_centerX);
        make.right.equalTo(self.mas_right);
        make.height.equalTo(@(self.height));
    }];
    
    [_centerLineView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.mas_top);
        make.centerX.equalTo(self.mas_centerX);
        make.width.equalTo(@2);
        make.height.equalTo(@(self.height));
    }];
    
    [_bottomLineView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.equalTo(self.mas_bottom);
        make.left.equalTo(self.mas_left);
        make.width.equalTo(@(self.width));
        make.height.equalTo(@2);
    }];
    
    _downLineView.frame = (CGRect){self.center.x / 2 - 20, self.bottom - 4, 40, 2};
}

#pragma mark - lazy load
- (UIButton *)countryInsideButton {
    if (!_countryInsideButton) {
        _countryInsideButton = [[UIButton alloc] init];
        _countryInsideButton.tag = 101;
        _countryInsideButton.titleLabel.font = kFont(17);
        [_countryInsideButton setTitleColor:kLYQBlue forState:UIControlStateNormal];
        [_countryInsideButton setTitle:@"国内" forState:UIControlStateNormal];
        [_countryInsideButton addTarget:self action:@selector(countryButtonClicked:) forControlEvents:UIControlEventTouchUpInside];
    }
    
    return _countryInsideButton;
}

- (UIButton *)countryOutsideButton {
    if (!_countryOutsideButton) {
        _countryOutsideButton = [[UIButton alloc] init];
        _countryOutsideButton.tag = 202;
        _countryOutsideButton.titleLabel.font = kFont(17);
        [_countryOutsideButton setTitleColor:kLYQBlue forState:UIControlStateNormal];
        [_countryOutsideButton addTarget:self action:@selector(countryButtonClicked:) forControlEvents:UIControlEventTouchUpInside];
        [_countryOutsideButton setTitle:@"国外" forState:UIControlStateNormal];
    }
    
    return _countryOutsideButton;
}

- (UIView *)centerLineView {
    if (!_centerLineView) {
        _centerLineView = [[UIView alloc] init];
        _centerLineView.backgroundColor = [UIColor lightGrayColor];
    }
    
    return _centerLineView;
}

- (UIView *)downLineView {
    if (!_downLineView) {
        _downLineView = [[UIView alloc] init];
        _downLineView.backgroundColor = kLYQBlue;
    }
    
    return _downLineView;
}

- (UIView *)bottomLineView {
    if (!_bottomLineView) {
        _bottomLineView = [[UIView alloc] init];
        _bottomLineView.backgroundColor = [UIColor lightGrayColor];
    }
    
    return _bottomLineView;
}

@end
